'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/zhifubao/kh/getzhifubao 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();

		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: ""
		};


		// 业务逻辑开始-----------------------------------------------------------
		const {
			CashOutInfo
		} = data

		if (!vk.pubfn.test(CashOutInfo.money, 'number')) {
			res.code = -1;
			res.msg = "金额类型错误";
			return res;
		}

		let ids = await vk.baseDao.adds({
			dbName: "a_tixian", // 表名
			dataJson: [{
				mod: CashOutInfo.mod,
				name: CashOutInfo.name,
				money: CashOutInfo.money * 1,
				account: CashOutInfo.account,
				remark: CashOutInfo.remark,
				status: 0, //0待审核，1已打款，2已驳回
				user_id: userInfo._id,
				username: userInfo.username
			}]
		});

		let reduceMoney = await db.collection('uni-id-users').doc(uid).update({
			money: _.inc(-CashOutInfo.money * 1)
		})



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
